package com.sugar.queryinfo.module.business.service.dataqueryqjld;

import com.sugar.queryinfo.module.business.controller.admin.data.dataqueryqjld.vo.DataQueryQjldPageReqVO;
import com.sugar.queryinfo.module.business.controller.admin.data.dataqueryqjld.vo.DataQueryQjldSaveReqVO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;

import com.sugar.queryinfo.module.business.dal.dataobject.dataqueryqjld.DataQueryQjldDO;
import com.sugar.queryinfo.framework.common.pojo.PageResult;
import com.sugar.queryinfo.framework.common.util.object.BeanUtils;

import com.sugar.queryinfo.module.business.dal.mysql.dataqueryqjld.DataQueryQjldMapper;

import static com.sugar.queryinfo.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.sugar.queryinfo.framework.common.util.collection.CollectionUtils.convertList;
import static com.sugar.queryinfo.module.business.enums.ErrorCodeConstants.*;

/**
 * 数据查询-全景雷达 Service 实现类
 *
 * @author Ysugar
 */
@Service
@Validated
public class DataQueryQjldServiceImpl implements DataQueryQjldService {

    @Resource
    private DataQueryQjldMapper dataQueryQjldMapper;

    @Override
    public Long createDataQueryQjld(DataQueryQjldSaveReqVO createReqVO) {
        // 插入
        DataQueryQjldDO dataQueryQjld = BeanUtils.toBean(createReqVO, DataQueryQjldDO.class);
        dataQueryQjldMapper.insert(dataQueryQjld);

        // 返回
        return dataQueryQjld.getId();
    }

    @Override
    public void updateDataQueryQjld(DataQueryQjldSaveReqVO updateReqVO) {
        // 校验存在
        validateDataQueryQjldExists(updateReqVO.getId());
        // 更新
        DataQueryQjldDO updateObj = BeanUtils.toBean(updateReqVO, DataQueryQjldDO.class);
        dataQueryQjldMapper.updateById(updateObj);
    }

    @Override
    public void deleteDataQueryQjld(Long id) {
        // 校验存在
        validateDataQueryQjldExists(id);
        // 删除
        dataQueryQjldMapper.deleteById(id);
    }

    @Override
        public void deleteDataQueryQjldListByIds(List<Long> ids) {
        // 删除
        dataQueryQjldMapper.deleteByIds(ids);
        }


    private void validateDataQueryQjldExists(Long id) {
        if (dataQueryQjldMapper.selectById(id) == null) {
            throw exception(DATA_QUERY_QJLD_NOT_EXISTS);
        }
    }

    @Override
    public DataQueryQjldDO getDataQueryQjld(Long id) {
        return dataQueryQjldMapper.selectById(id);
    }

    @Override
    public PageResult<DataQueryQjldDO> getDataQueryQjldPage(DataQueryQjldPageReqVO pageReqVO) {
        return dataQueryQjldMapper.selectPage(pageReqVO);
    }

}